﻿using BBICMS.Model;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace BBICMS.Repository.Configuration
{
    public class AdvertisementConfiguration : EntityTypeConfiguration<Advertisement>
    {
        public AdvertisementConfiguration()
        {
            this.HasKey(p => p.Id);

            this.Property(p => p.Id)
            //    .HasColumnName("SlideID")
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.ToTable("Advertisements");

            this.Property(p => p.Title).HasMaxLength(100).IsRequired();  
            this.Property(p => p.PositionId).IsRequired();
            this.Property(p => p.SmallImgUrl).HasMaxLength(150).IsOptional();
            this.Property(p => p.FullImgUrl).HasMaxLength(150).IsOptional();
            this.Property(p => p.WebLink).HasMaxLength(150).IsOptional(); 
            this.Property(p => p.AddedDate).IsRequired().HasColumnType("datetime");
            this.Property(p => p.AddedBy).HasMaxLength(50);
            this.Property(p => p.UpdatedDate).IsOptional().HasColumnType("datetime");
            this.Property(p => p.UpdatedBy).IsOptional().HasMaxLength(50);

            this.HasRequired(p => p.Position)
            .WithMany(h=>h.Advertisements)
            .HasForeignKey(p => p.PositionId);  
        }
    }
}
